#include<iostream>
#include<list>
using namespace std;


class abstractObserver	//观测者抽象接口
{
public:
	virtual void observedAndDoSomething() = 0;
	virtual ~abstractObserver() {};
};
class ObserverA :public abstractObserver
{
public:
	void observedAndDoSomething()
	{
		cout << "A has observed,and do somethings" << endl;
	}
};
class ObserverB :public abstractObserver
{
public:
	void observedAndDoSomething()
	{
		cout << "B has observed,and do somethings" << endl;
	}
};

class eventGenerator	//生成对象的类-也可以直接当做基类使用啊
{
private:
	list<abstractObserver*> Observerlist;

public:
	void startAEvent()
	{
		onEvent();
	}
	void addObserver(abstractObserver* observer)
	{
		Observerlist.push_back(observer);
	}
	void removeObserver()
	{
		Observerlist.pop_back();
	}

protected:
	virtual void onEvent()
	{
		list<abstractObserver*>::iterator iter = Observerlist.begin();
		while (iter != Observerlist.end())
		{
			(*iter)->observedAndDoSomething();
			iter++;
		}
	}
};

int main()
{
	ObserverA A;
	ObserverB B;
	eventGenerator E;
	E.addObserver(&A);
	E.startAEvent();
	E.addObserver(&B);
	E.startAEvent();
}